package com.bird.generate.ddd.domain.generateutil

import com.bird.generate.ddd.domain.AggregateRootEntity
import com.bird.generate.ddd.domain.appendNextPath
import com.bird.generate.ddd.domain.createFile

class ModuleGenerate {

    companion object {
        /**
         * 生成remote代码
         */
        fun moduleGenerate(path: String,aggregateRoot: AggregateRootEntity) {
            var moduleRootPath = path.appendNextPath(aggregateRoot.moduleName.lowercase())+"bc"
            //创建pom.xml
            generateMoudlePomXml(aggregateRoot,moduleRootPath)


        }

        private fun generateMoudlePomXml(
            aggregateRoot: AggregateRootEntity,
            path: String
        ) {
            val xmlContent =
"""<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>${aggregateRoot.comPrefix}</groupId>
        <artifactId><!-- todo --></artifactId>
        <version>${aggregateRoot.version}</version>
    </parent>

    <artifactId>${aggregateRoot.moduleName.lowercase()}bc</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>${aggregateRoot.moduleName.lowercase()}bc-domain</module>
        <module>${aggregateRoot.moduleName.lowercase()}bc-northbound</module>
        <module>${aggregateRoot.moduleName.lowercase()}bc-southbound</module>
        <module>${aggregateRoot.moduleName.lowercase()}bc-client</module>
    </modules>
    <dependencies>
        <dependency>
            <groupId>com.cebpubservice</groupId>
            <artifactId>zz-common</artifactId>
            <version>${'$'}{zz.project.version}</version>
        </dependency>
    </dependencies>
</project>
                """
            createFile(path.appendNextPath("pom.xml"), xmlContent)
        }

    }

}